/*
 *
 *  Connection Manager
 *
 *  Copyright (C) 2007-2009  Intel Corporation. All rights reserved.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */

#ifndef __CONNMAN_SERVICE_H
#define __CONNMAN_SERVICE_H

#include <gdbus.h>

#include <connman/types.h>

#ifdef __cplusplus
extern "C" {
#endif

/**
 * SECTION:service
 * @title: Service primitives
 * @short_description: Functions for handling services
 */

enum connman_service_type {
	CONNMAN_SERVICE_TYPE_UNKNOWN   = 0,
	CONNMAN_SERVICE_TYPE_ETHERNET  = 1,
	CONNMAN_SERVICE_TYPE_WIFI      = 2,
	CONNMAN_SERVICE_TYPE_WIMAX     = 3,
	CONNMAN_SERVICE_TYPE_BLUETOOTH = 4,
	CONNMAN_SERVICE_TYPE_CELLULAR  = 5,
	CONNMAN_SERVICE_TYPE_VPN       = 6,

	CONNMAN_SERVICE_TYPE_MAX
};

enum connman_service_mode {
	CONNMAN_SERVICE_MODE_UNKNOWN = 0,
	CONNMAN_SERVICE_MODE_MANAGED = 1,
	CONNMAN_SERVICE_MODE_ADHOC   = 2,
};

enum connman_service_security {
	CONNMAN_SERVICE_SECURITY_UNKNOWN = 0,
	CONNMAN_SERVICE_SECURITY_NONE    = 1,
	CONNMAN_SERVICE_SECURITY_WEP     = 2,
	CONNMAN_SERVICE_SECURITY_WPA     = 3,
	CONNMAN_SERVICE_SECURITY_RSN     = 4,
	CONNMAN_SERVICE_SECURITY_802_1X  = 5,
	CONNMAN_SERVICE_SECURITY_PSK     = 6,

	CONNMAN_SERVICE_SECURITY_MAX
};

enum connman_service_state {
	CONNMAN_SERVICE_STATE_UNKNOWN       = 0,
	CONNMAN_SERVICE_STATE_IDLE          = 1,
	CONNMAN_SERVICE_STATE_CARRIER       = 2,
	CONNMAN_SERVICE_STATE_ASSOCIATION   = 3,
	CONNMAN_SERVICE_STATE_CONFIGURATION = 4,
	CONNMAN_SERVICE_STATE_READY         = 5,
	CONNMAN_SERVICE_STATE_PORTAL        = 6,
	CONNMAN_SERVICE_STATE_ONLINE        = 7,
	CONNMAN_SERVICE_STATE_DISCONNECT    = 8,
	CONNMAN_SERVICE_STATE_FAILURE       = 9,
	CONNMAN_SERVICE_STATE_ACTIVATION_FAILURE  = 10,

	CONNMAN_SERVICE_STATE_MAX
};

enum connman_service_connectivity_state {

	/*
	 * The connectivity state is unknown.  This state is set for a
	 * ready service that is not the default service.  It is also
	 * the state from after the service becomes ready until a
	 * more exact state can be established.
	 */
	CONNMAN_SERVICE_CONNECTIVITY_STATE_UNKNOWN      = 0,

	/* No known issues making DNS and HTTP requests */
	CONNMAN_SERVICE_CONNECTIVITY_STATE_UNRESTRICTED = 1,

	/* Can only access a captive portal website */
	CONNMAN_SERVICE_CONNECTIVITY_STATE_RESTRICTED   = 2,

	/*
	 * Inside a captive portal with an IP address assigned but DNS
	 * and HTTP requests fail.
	 */
	CONNMAN_SERVICE_CONNECTIVITY_STATE_NONE         = 3,

	CONNMAN_SERVICE_CONNECTIVITY_STATE_MAX
};

enum connman_service_error {
	CONNMAN_SERVICE_ERROR_NO_ERROR               = 0,
	CONNMAN_SERVICE_ERROR_OUT_OF_RANGE           = 1,
	CONNMAN_SERVICE_ERROR_PIN_MISSING            = 2,
	CONNMAN_SERVICE_ERROR_DHCP_FAILED            = 3,
	CONNMAN_SERVICE_ERROR_CONNECT_FAILED         = 4,
	CONNMAN_SERVICE_ERROR_BAD_PASSPHRASE         = 5,
	CONNMAN_SERVICE_ERROR_BAD_WEPKEY             = 6,
	CONNMAN_SERVICE_ERROR_ACTIVATION_FAILED      = 7,
	CONNMAN_SERVICE_ERROR_NEED_EVDO              = 8,
	CONNMAN_SERVICE_ERROR_NEED_HOME_NETWORK      = 9,
	CONNMAN_SERVICE_ERROR_OTASP_FAILED           = 10,
	CONNMAN_SERVICE_ERROR_AAA_FAILED             = 11,
	CONNMAN_SERVICE_ERROR_INTERNAL               = 12,
	CONNMAN_SERVICE_ERROR_DNS_LOOKUP_FAILED      = 13,
	CONNMAN_SERVICE_ERROR_HTTP_GET_FAILED        = 14,
	CONNMAN_SERVICE_ERROR_IPSEC_PSK_AUTH_FAILED  = 15,
	CONNMAN_SERVICE_ERROR_IPSEC_CERT_AUTH_FAILED = 16,
	CONNMAN_SERVICE_ERROR_PPP_AUTH_FAILED        = 17,

	CONNMAN_SERVICE_ERROR_MAX
};

struct connman_service;

struct connman_service *connman_service_create(void);
struct connman_service *connman_service_ref(struct connman_service *service);
void connman_service_unref(struct connman_service *service);

const char *connman_service_get_identifier(const struct connman_service *
						service);
connman_bool_t connman_service_get_autoconnect(const struct connman_service *
						service);
void connman_service_auto_connect(struct connman_service *);

connman_bool_t connman_service_get_favorite(const struct connman_service *
						service);
int connman_service_set_favorite(struct connman_service *service,
						connman_bool_t favorite);

connman_bool_t connman_service_get_previously_connected(
				const struct connman_service * service);
int connman_service_set_previously_connected(struct connman_service *service,
				connman_bool_t previously_connected);

void connman_service_set_connectivity_state(struct connman_service *service,
		      enum connman_service_connectivity_state connectivity);

struct connman_device;
struct connman_device *connman_service_get_device(const struct connman_service
						*service);
const char *connman_service_get_interface(const struct connman_service
						*service);
const char *connman_service_get_state(const struct connman_service *service);
const char *connman_service_get_type(const struct connman_service *service);

struct connman_network;
struct connman_service *connman_service_lookup_from_network(struct
						connman_network *network);
void connman_service_set_current_network(struct connman_network *network);

void connman_service_get_time(const struct connman_service *service,
						enum connman_service_state,
						long *sec, long *usec);
void connman_service_get_time_delta(const struct connman_service *service,
						enum connman_service_state from,
						enum connman_service_state to,
						long *sec, long *usec);

enum connman_service_error connman_service_get_error(const struct
						connman_service *service);

int connman_service_get_frequency(const struct connman_service *service);
enum connman_network_phymode;
enum connman_network_phymode connman_service_get_phymode(const struct
						connman_service *service);
enum connman_service_security connman_service_get_security(const struct
						connman_service *service);
const char *connman_service_get_authmode(const struct connman_service *service);

struct connman_network_apn;

const struct connman_network_apn *connman_service_get_last_good_apn(
	const struct connman_service *service);

const char *connman_service_get_usage_url(const struct connman_service
						*service);

void connman_service_create_sticky_route(struct connman_service *service,
						const char *ip_addr);

const char *connman_service_get_sticky_route(const struct connman_service
						*service);

#ifdef __cplusplus
}
#endif

#endif /* __CONNMAN_SERVICE_H */
